!function (e) {
	e.banner = function(el,options){
		var that = this;
		
		// 获取对象
		this.el = $(el);
		//获取banner数量
		this.length = this.el.find('.dm-bannerBox').children().length ;
		
		this.index = 0;
		
		this.options = options == undefined ? this.options = {} : this.options = options ;
		// 启用锚点
		this.options.dot == undefined ? this.options.dot = true : this.options.dot ;
		//轮播时间
		this.options.loop == undefined ? this.options.loop = 3000 : this.options.loop ;
		//左右切换
		this.options.tap == undefined ? this.options.tab = true : this.options.tab ;
		
		this.init();
		
		window.onresize = function (){
			that.init();
		};
		
		//锚点
		if(this.options.dot){
			var dotNode = document.createElement('div');
			dotNode.className = 'dot';
			for(var i=0;i<this.length;i++){
				var item = document.createElement('span');
				item.setAttribute('data-index',i);
				item.className = 'ani';
				if(i==0){
					item.className = 'on ani';
				};
				dotNode.appendChild(item);
				item.onclick = function(){
					that.index = this.getAttribute('data-index');
					that.tabFunc();
					if(typeof that.options.callback == 'function'){
						that.options.callback(that.index);
					};
				};
			};
			this.el[0].appendChild(dotNode);
		};
		
		//左右切换
		if(this.options.tab){
			var prev = document.createElement('div');
			var next = document.createElement('div');
			if(that.index == 0){
				prev.style.opacity = '0.5';
			};
			prev.className = 'prev-btn tab-btn';
			next.className = 'next-btn tab-btn';
			
			this.el[0].appendChild(prev);
			this.el[0].appendChild(next);
			
			next.onclick = function(){
				that.index < that.length-1 ? that.index++ : '';
				that.tabFunc();
			};
			
			prev.onclick = function(){
				that.index > 0 ? that.index-- : '';
				that.tabFunc();
			};
		};
		
	};
	e.banner.prototype.init = function(){
		this.el.find('.dm-bannerBox').children().width( this.el.width() );
	};
	e.banner.prototype.tabFunc = function(){
		this.el.find('.dm-bannerBox').css({
			'marginLeft':'-'+this.el.width()*this.index+'px'
		});
		
		if(this.options.dot){
			this.el.find('.dot').children().eq(this.index).addClass('on').siblings().removeClass('on');
		};
		
		if(this.options.tab){
			if(this.index == 0){
				this.el.find('.prev-btn').css('opacity','0.5');
			}else if(this.index == this.length - 1){
				this.el.find('.next-btn').css('opacity','0.5');
			}else{
				this.el.find('.tab-btn').css('opacity','1');
			};
		};
	};
	
	return e.banner;
}(window);